import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.swing.*;

/*
 * Things not yet done:
 *  - GUI for the incentives part
 *  - GUI for the notes part
 *  - Saving to the struct Files
 *  - Connection of Vector Varaibles with the tables
 *  - Vector and SQL Updates
 *  - Incentives - checking for qualification
 *  - Incentives - letter generation
 *  - loading of file from attendance/remote app (FILE HANDLING and LINKING)
 *  - loading of CSV file to generate new database (FILE HANDLING and algorithm)
 *  - generating (new) file (FILE HANDLING)
 *  - login system (simple password design)
 */

/**
 * GUI class handler for the Main Application
 * @author CLLM
 *
 */
public class MainAppGui extends JFrame implements ActionListener, WindowListener{
	private int currentPanel = 0; //To determine current GUI to display
	private int addEditFlag = 0; //Flag for the database Control (0 - Add, 1 - Edit)
	private Calendar curTime = Calendar.getInstance();	//For clock
	private SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss MM-dd-yyyy"); //For the output of the clock

	///////////////////////////////////////////////////////////////////////////////////// GUI COMPONENTS
	private ImageIcon save, defaulty, cancel, edit, exit, write, load, new1, mem, courses, incentives, notes, back, del, add, ok; //ImageIcons for the JButton
	private Image imgSave, imgCancel, imgEdit, imgLoad, imgNew, imgBack, imgExit, imgWrite, imgNotes, imgMem, imgCourses, imgIncentives, imgAdd, imgOK, imgDel; //Actual Image for ImageIcon
	private JPanel newDatabaseViaManualPanel, newAppPanel, newDatabaseViaCSVPanel, mainMenuPanel, modifyPanel, coursesAppPanel, addcoursePanel; //JPanel for each User Interface
	private JFrame addMemberFrame, mainFrame,  modifyFrame, databaseFrame, coursesFrame, newDatabaseFileframe, newDatabaseViaCSVFrame, newDatabaseViaManualFrame, addcourseFrame; //JFrame
	
	//////////// JLabel
	private JLabel saveAs, lblDateTime, lblDetailManual, lblLoadCSV, lblmodify, labelCSV, lblSQL, lblLoadFrom,  lblSaveAs;	//JLabel
	private JLabel fill, fname, mname, course, bday, lname, idnum, email, contact, rank, subject, other; //JLabel in Member Adding/Modifying
	private JLabel coursecode, section, professor, college, department; //JLabel for Course Adding/Modifying 
	/////////// JTextField
	private JTextField FnameText, MnameText, LnameText, courseText, idnumText, emailText, contactText, otherText; //JTextField in Database Table Control
	private JTextField txtSave, txtLoad; //JTextField for File Handling
	
	/////////// JButton
	private JButton btnSave, btnNew, btnEdit, btnLoad, btnExit, btnNCreate, btnAdd, btnDel, btnOK, btnS, btnL, btnC, btnD; //JButtons
	private JButton btnBrowse, btnDefault, btnMembers, btnCourses, btnIncentives, btnNotes, btnBack, btnCancel; //JButtons

	////////// JComboBox
	private JComboBox ranks, month, day, year, user; //JCombobox for Member's adding/modifying controls
	private JComboBox name;	//JCombobox for Course adding/modifying controls
	
	JTextField coursecodeText, sectionText, professorText, collegeText, departmentText;
	private File fLocation, fLoad;
	private JTable membersTable, coursesTable;
	private JScrollPane scrollPane;
	private JPanel databaseAppPanel;
	private Font f;
	private String [] monthName = {"Jan","Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"}; //For combobox (month)
	////////////////////////////////////////////////////////////////////////// END OF GUI COMPONENTS

	JPanel addPanel;

	/**
	 * MainAppGui (CONSTRUCTOR)
	 *  Initialization for the GUI of the application.
	 */
	public MainAppGui(){
		initImage();
		initJFrame();
		mainMenuPanel();
	}

	/**
	 * initJFrame()
	 * 	Initialize the JFrame of each respective interface
	 */
	private void initJFrame(){
		mainFrame = new JFrame("~ AdCreate ~  Main Application");
		modifyFrame = new JFrame("~ AdCreate ~  Modify Database ");	
		databaseFrame = new JFrame("~ AdCreate ~  (Members)");
		coursesFrame = new JFrame("~ AdCreate ~   (Courses)");
		newDatabaseFileframe = new JFrame("~ AdCreate ~ New Database");
		newDatabaseViaCSVFrame = new JFrame("New Database (CSV)");
		newDatabaseViaManualFrame = new JFrame("New Database (Manual)");
		addMemberFrame = new JFrame("~ AdCreate ~ Modify Database ");
		addcourseFrame = new JFrame("~ AdCreate ~ Modify Database ");
	}

	/**
	 * initImage()
	 * 	Initialize(Load) the images to the respective Image Variable
	 */
	private void initImage(){
		imgEdit = getToolkit().createImage("img/edit.png");
		imgLoad = getToolkit().createImage("img/load.png");
		imgNew = getToolkit().createImage("img/new.png");
		imgBack = getToolkit().createImage("img/back.png");
		imgExit = getToolkit().createImage("img/exit.png");
		imgSave = getToolkit().createImage("img/save.png");
		imgNotes = getToolkit().createImage("img/notes.png");
		imgMem = getToolkit().createImage("img/members.png");
		imgCourses = getToolkit().createImage("img/course.png");
		imgIncentives = getToolkit().createImage("img/incentives.png");
		imgOK = getToolkit().createImage("img/ok.png");
		imgAdd = getToolkit().createImage("img/add.png");
		imgDel = getToolkit().createImage("img/del.png");
		imgWrite = getToolkit().createImage("img/write.png");
		imgCancel = getToolkit().createImage("img/cancel.png");
	}

	/**
	 * mainMenuPanel()
	 *  Main Menu GUI
	 *  @no	1
	 */
	public void mainMenuPanel()
	{  
		currentPanel = 1;	// Set the current GUI to main menu (1)

		Image newimg = imgExit.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH) ;  
		exit = new ImageIcon( newimg );
		Image newimg2 = imgEdit.getScaledInstance(25, 25, java.awt.Image.SCALE_SMOOTH) ;  
		edit = new ImageIcon( newimg2 );
		Image newimg3 = imgLoad.getScaledInstance(30, 30, java.awt.Image.SCALE_SMOOTH) ;  
		load = new ImageIcon( newimg3 );
		Image newimg4 = imgNew.getScaledInstance(30, 30, java.awt.Image.SCALE_SMOOTH) ;  
		new1 = new ImageIcon( newimg4 );	

		System.out.println(dateFormat.format(curTime.getTime()));
		JFrame.setDefaultLookAndFeelDecorated(false);
		mainFrame.addWindowListener(this);
		mainFrame.setLayout(null);
		mainFrame.setSize(300,300);
		mainFrame.setResizable(false);
		mainFrame.setLocationRelativeTo(null);
		mainFrame.setVisible(true);
		mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

		JPanel primaryPanel = new JPanel();
		primaryPanel.setLayout(null);
		mainFrame.setContentPane(primaryPanel);

		Date today = new Date();
		JLabel label = new JLabel();
		label.setText(today.toString()); 
		primaryPanel.add(label);
		label.setBounds(185, 5, 170, 15);

		btnNew = new JButton ("Create New Database");
		btnEdit = new JButton ("Modify Default Database");
		btnExit = new JButton ("Exit");

		mainMenuPanel = new JPanel();
		mainMenuPanel.setLocation(20, 20);
		mainMenuPanel.setSize(300, 300);
		mainMenuPanel.setLayout(null);

		btnNew.addActionListener(this);
		btnNew.setBounds(10, 70, 205, 35);
		btnEdit.addActionListener(this);
		btnEdit.setBounds(10, 130, 205, 35);
		btnExit.addActionListener(this);
		btnExit.setBounds(160, 200, 90, 30);

		btnExit.setIcon(exit);
		btnEdit.setIcon(edit);
		btnNew.setIcon(new1);

		mainMenuPanel.add(btnNew);
		mainMenuPanel.add(btnEdit);
		mainMenuPanel.add(btnExit);
		primaryPanel.add(mainMenuPanel);

	}

	/**
	 * newDatabaseCreationPanel()
	 *  New Database GUI
	 *  @no	7
	 */
	public void newDatabaseCreationPanel(){
		currentPanel = 7;	// Set the current GUI to new database file menu (7)
		newAppPanel = new JPanel();
		newAppPanel.setLayout(null);

		Image newimg = imgExit.getScaledInstance(17, 17, java.awt.Image.SCALE_SMOOTH) ;  
		exit = new ImageIcon( newimg );

		Image newimg2 = imgBack.getScaledInstance(14, 14, java.awt.Image.SCALE_SMOOTH) ;  
		back = new ImageIcon( newimg2 );

		Image newimg3 = imgWrite.getScaledInstance(35, 35, java.awt.Image.SCALE_SMOOTH) ;  
		write = new ImageIcon( newimg3 );

		Image newimg4 = imgLoad.getScaledInstance(40, 40, java.awt.Image.SCALE_SMOOTH) ;  
		load = new ImageIcon( newimg4 );

		JFrame.setDefaultLookAndFeelDecorated(false);		
		newDatabaseFileframe.setLayout(null);		
		newDatabaseFileframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		newDatabaseFileframe.setSize(300, 220);
		newDatabaseFileframe.setResizable(false);
		newDatabaseFileframe.setLocationRelativeTo(null);
		newDatabaseFileframe.setVisible(true);
		newDatabaseFileframe.setContentPane(newAppPanel);

		btnSave = new JButton();
		btnLoad = new JButton ();
		btnBack = new JButton ("Back");

		lblDetailManual = new JLabel("Enter details manually");
		lblLoadCSV = new JLabel("Load from CSV");

		btnSave.addActionListener(this);
		btnSave.setBounds(20, 20, 40, 40);
		btnLoad.addActionListener(this);
		btnLoad.setBounds(20, 75, 40, 40);
		btnBack.addActionListener(this);
		btnBack.setBounds(195, 150, 85, 20);

		lblDetailManual.setBounds(68,28,180,20);
		lblLoadCSV.setBounds(68,85,180,20);		

		btnBack.setIcon(back);
		btnSave.setIcon(write);
		btnLoad.setIcon(load);

		newAppPanel.add(lblDetailManual);	
		newAppPanel.add(lblLoadCSV);	
		newAppPanel.add(btnSave);
		newAppPanel.add(btnLoad);
		newAppPanel.add(btnBack);
	}

	/**
	 * newDatabaseCreationFromNewPanel()
	 *  New Database File GUI based on a CSV excel generated file
	 *  @no	8
	 */
	public void newDatabaseCreationFromNewPanel(){
		currentPanel = 8;
		newDatabaseViaManualPanel = new JPanel();
		newDatabaseViaManualPanel.setLayout(null);

		Image newimg = imgOK.getScaledInstance(17, 17, java.awt.Image.SCALE_SMOOTH) ;  
		ok = new ImageIcon( newimg );
		Image newimg2 = imgCancel.getScaledInstance(15, 15, java.awt.Image.SCALE_SMOOTH) ;  
		cancel = new ImageIcon( newimg2 );

		JFrame.setDefaultLookAndFeelDecorated(false);		
		newDatabaseViaManualFrame.setLayout(null);		
		newDatabaseViaManualFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		newDatabaseViaManualFrame.setSize(380, 165);
		newDatabaseViaManualFrame.setResizable(false);
		newDatabaseViaManualFrame.setLocationRelativeTo(null);
		newDatabaseViaManualFrame.setVisible(true);
		newDatabaseViaManualFrame.setContentPane(newDatabaseViaManualPanel);

		btnS = new JButton("Browse");
		btnOK = new JButton ("OK");
		btnC = new JButton ("Cancel");
		btnD = new JButton ("Default");

		btnS.setMnemonic('s');
		btnS.addActionListener(this);
		btnS.setBounds(280, 40, 80, 20);

		btnD.setMnemonic('d');
		btnD.addActionListener(this);
		btnD.setBounds(20, 90, 80, 20);

		btnOK.setMnemonic('o');
		btnOK.addActionListener(this);
		btnOK.setBounds(140, 90, 80, 20);

		btnC.setMnemonic('c');
		btnC.addActionListener(this);
		btnC.setBounds(260, 90, 95, 20);

		saveAs = new JLabel("Save As..");

		txtSave = new JTextField();

		saveAs.setBounds(20,40,180,20);

		txtSave.setBounds(90,40,180,20);

		btnOK.setIcon(ok);
		btnC.setIcon(cancel);

		newDatabaseViaManualPanel.add(btnS);	
		newDatabaseViaManualPanel.add(btnD);
		newDatabaseViaManualPanel.add(btnOK);
		newDatabaseViaManualPanel.add(btnC);
		newDatabaseViaManualPanel.add(saveAs);
		newDatabaseViaManualPanel.add(txtSave);
	}

	/**
	 * newDatabaseCreationFromCSVPanel()
	 *  New Database File GUI based on a CSV excel generated file
	 *  @no	9
	 */
	public void newDatabaseCreationFromCSVPanel(){
		currentPanel = 9;
		newDatabaseViaCSVPanel = new JPanel();
		newDatabaseViaCSVPanel.setLayout(null);

		Image newimg = imgOK.getScaledInstance(17, 17, java.awt.Image.SCALE_SMOOTH) ;  
		ok = new ImageIcon( newimg );
		Image newimg2 = imgCancel.getScaledInstance(15, 15, java.awt.Image.SCALE_SMOOTH) ;  
		cancel = new ImageIcon( newimg2 );

		JFrame.setDefaultLookAndFeelDecorated(false);		
		newDatabaseViaCSVFrame = new JFrame("New Database (CSV)");
		newDatabaseViaCSVFrame.setLayout(null);		
		newDatabaseViaCSVFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		newDatabaseViaCSVFrame.setSize(398, 210);
		newDatabaseViaCSVFrame.setResizable(false);
		newDatabaseViaCSVFrame.setLocationRelativeTo(null);
		newDatabaseViaCSVFrame.setVisible(true);
		newDatabaseViaCSVFrame.setContentPane(newDatabaseViaCSVPanel);

		btnS = new JButton("Browse");
		btnL = new JButton("Browse");
		btnOK = new JButton ("OK");
		btnC = new JButton ("Cancel");
		btnD = new JButton ("Default");

		btnS.addActionListener(this);
		btnS.setBounds(280, 105, 95, 20);
		btnL.addActionListener(this);
		btnL.setBounds(280, 40, 95, 20);
		btnD.addActionListener(this);
		btnD.setBounds(40, 145, 80, 20);
		btnOK.addActionListener(this);
		btnOK.setBounds(160, 145, 80, 20);
		btnC.addActionListener(this);
		btnC.setBounds(280, 145, 95, 20);

		labelCSV = new JLabel("CSV");
		lblSQL = new JLabel("SQL");
		lblLoadFrom = new JLabel("Load From..");
		lblSaveAs = new JLabel("Save As..");

		txtSave = new JTextField();
		txtLoad = new JTextField();

		labelCSV.setBounds(10,20,180,20);
		lblSQL.setBounds(10,85,175,20);
		lblLoadFrom.setBounds(20,40,180,20);
		lblSaveAs.setBounds(20,105,180,20);

		txtSave.setBounds(90,40,180,20);
		txtLoad.setBounds(90,105,180,20);

		btnOK.setIcon(ok);
		btnC.setIcon(cancel);

		newDatabaseViaCSVPanel.add(btnS);	
		newDatabaseViaCSVPanel.add(btnL);	
		newDatabaseViaCSVPanel.add(btnD);
		newDatabaseViaCSVPanel.add(btnOK);
		newDatabaseViaCSVPanel.add(btnC);
		newDatabaseViaCSVPanel.add(labelCSV);
		newDatabaseViaCSVPanel.add(lblSQL);
		newDatabaseViaCSVPanel.add(lblLoadFrom);
		newDatabaseViaCSVPanel.add(lblSaveAs);
		newDatabaseViaCSVPanel.add(txtSave);
		newDatabaseViaCSVPanel.add(txtLoad);
	}

	/**
	 * modifyDatabaseMenuUI(File fLocation)
	 *  Initialization of the UI from loading a specific file for the menu of the modification of the database part
	 *  @param fLocation
	 *  @no 2
	 */
	public void modifyDatabaseMenuUIPanel(File fLocation){
		this.fLocation = fLocation;
		modifyDatabaseMenuPanel();
	}

	/**
	 * modifyDatabaseMenuUI()
	 * 	Initialization of the UI for the menu of the modification of the database part
	 *  @no 2
	 */
	public void modifyDatabaseMenuPanel(){
		currentPanel = 2;	// Set the current GUI to Modify Database menu (2)
		Boolean loadSucess = true;
		modifyPanel = new JPanel();
		modifyPanel.setLayout(null);

		Image newimg = imgBack.getScaledInstance(15, 15, java.awt.Image.SCALE_SMOOTH) ;  
		back = new ImageIcon( newimg );
		Image newimg2 = imgMem.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH) ;  
		mem = new ImageIcon( newimg2 );
		Image newimg3 = imgExit.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH) ;  
		//		exit = new ImageIcon( newimg3 );
		Image newimg4 = imgCourses.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH) ;  
		courses = new ImageIcon( newimg4 );
		Image newimg5 = imgIncentives.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH) ;  
		incentives = new ImageIcon( newimg5 );
		Image newimg6 = imgNotes.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH) ;  
		notes = new ImageIcon( newimg6 );

		JFrame.setDefaultLookAndFeelDecorated(false);
		modifyFrame.setLayout(null);
		modifyFrame.setSize(385,255);
		modifyFrame.setResizable(false);
		modifyFrame.setLocationRelativeTo(null);
		modifyFrame.setVisible(true);
		modifyFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		modifyFrame.setContentPane(modifyPanel);

		btnMembers = new JButton("  Members");
		btnCourses = new JButton ("  Courses");
		btnIncentives = new JButton (" Incentives");
		btnNotes = new JButton (" Notes");
		btnBack = new JButton ("  Back");
		//		btnExit = new JButton ("  Exit");
		btnBrowse = new JButton ("...");
		btnDefault = new JButton ("Set as Default");

		if(loadSucess){
			btnMembers.setEnabled(true);
			btnCourses.setEnabled(true);
			btnIncentives.setEnabled(true);
			btnNotes.setEnabled(true);
		}
		else{
			btnMembers.setEnabled(false);
			btnCourses.setEnabled(false);
			btnIncentives.setEnabled(false);
			btnNotes.setEnabled(false);
		}

		lblmodify = new JLabel("Database to be Modified:");
		name = new JComboBox();

		name.setEditable(false);

		name.setBounds(165, 25, 170, 20);
		lblmodify.setBounds(20, 20, 140, 30);

		btnBrowse.setMnemonic('b');
		btnBrowse.addActionListener(this);
		btnBrowse.setBounds(340, 25, 30, 20);

		btnDefault.setMnemonic('d');
		btnDefault.addActionListener(this);
		btnDefault.setBounds(190, 55, 120, 18);

		btnMembers.setMnemonic('m');
		btnMembers.addActionListener(this);
		btnMembers.setBounds(55, 90, 125, 30);

		btnCourses.setMnemonic('c');
		btnCourses.addActionListener(this);
		btnCourses.setBounds(55, 130, 125, 30);

		btnIncentives.setMnemonic('i');
		btnIncentives.addActionListener(this);
		btnIncentives.setBounds(205, 90, 125, 30);

		btnNotes.setMnemonic('n');
		btnNotes.addActionListener(this);
		btnNotes.setBounds(205, 130, 125, 30);

		btnBack.setMnemonic('b');
		btnBack.addActionListener(this);
		btnBack.setBounds(15, 185, 95, 20);

		//		btnExit.setMnemonic('x');
		//		btnExit.addActionListener(this);
		//		btnExit.setBounds(260, 185, 95, 30);

		btnMembers.setIcon(mem);
		btnBack.setIcon(back);
		//		btnExit.setIcon(exit);
		btnCourses.setIcon(courses);
		btnNotes.setIcon(notes);
		btnIncentives.setIcon(incentives);

		modifyPanel.add(btnBrowse);
		modifyPanel.add(btnDefault);
		modifyPanel.add(btnMembers);	
		modifyPanel.add(btnCourses);	
		modifyPanel.add(btnIncentives);
		modifyPanel.add(btnNotes);
		modifyPanel.add(btnBack);
		//		modifyPanel.add(btnExit);
		modifyPanel.add(name);
		modifyPanel.add(lblmodify);
	}

	public void memberDatabaseMenuPanel(){
		currentPanel = 3;	// Set the current GUI to the member's database menu screen(3)
		boolean DEBUG = false;

		databaseAppPanel = new JPanel();
		databaseAppPanel.setLayout(null);

		Image newimg = imgOK.getScaledInstance(17, 17, java.awt.Image.SCALE_SMOOTH) ;  
		ok = new ImageIcon( newimg );
		//Image newimg2 = imgBack.getScaledInstance(17, 17, java.awt.Image.SCALE_SMOOTH) ;  
		//back = new ImageIcon( newimg2 );
		Image newimg3 = imgExit.getScaledInstance(17, 17, java.awt.Image.SCALE_SMOOTH) ;  
		exit = new ImageIcon( newimg3 );
		Image newimg4 = imgAdd.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH) ;  
		add = new ImageIcon( newimg4 );
		Image newimg5 = imgEdit.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH) ;  
		edit = new ImageIcon( newimg5 );
		Image newimg6 = imgDel.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH) ;  
		del = new ImageIcon( newimg6 );

		JFrame.setDefaultLookAndFeelDecorated(false);		
		databaseFrame.setLayout(null);		
		databaseFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		databaseFrame.setSize(730, 430);
		databaseFrame.setResizable(false);
		databaseFrame.setLocationRelativeTo(null);
		databaseFrame.setVisible(true);
		databaseFrame.setContentPane(databaseAppPanel);

		Date today = new Date();
		JLabel label = new JLabel();
		label.setText(today.toString()); 
		databaseAppPanel.add(label);
		label.setBounds(615, 5, 170, 15);

		btnAdd = new JButton("  Add");
		btnDel = new JButton("  Delete");
		btnEdit = new JButton("  Modify");
		btnOK = new JButton ("  OK");
		//btnBack = new JButton ("  Back");


		btnOK.setMnemonic('o');
		btnOK.addActionListener(this);
		btnOK.setBounds(580, 345, 120, 30);

		//btnBack.setMnemonic('b');
		//btnBack.addActionListener(this);
		//btnBack.setBounds(20, 345, 120, 30);

		btnDel.setMnemonic('d');
		btnDel.addActionListener(this);
		btnDel.setBounds(20, 230, 120, 30);

		btnEdit.setMnemonic('m');
		btnEdit.addActionListener(this);
		btnEdit.setBounds(20, 180, 120, 30);

		btnAdd.setMnemonic('a');
		btnAdd.addActionListener(this);
		btnAdd.setBounds(20, 130, 120, 30);

		btnOK.setIcon(ok);
		btnBack.setIcon(back);
		btnAdd.setIcon(add);
		btnDel.setIcon(del);
		btnEdit.setIcon(edit);

		Object rowData[][] = { { "11012111", "COJUANCO", "ANDREW", "DY", "andrecu@cllm.com"," ","Member", "CSE", "--"},
				{ "11013421", "GONZALEZ", "JOSEPH", "TAN", "gonzalezjotan@cllm.com"," ", "Member","", "--"} };
		Object columnNames[] = { "ID Number", "Last Name", "First Name", "Middle Name", "E-mail Address", "Contact Number(s)", "Rank", "Subject(s)", "Other Information"};
		JTable table = new JTable(rowData, columnNames);
		JScrollPane scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

		scrollPane.setBounds(150, 100, 550, 230);
		scrollPane.setVisible(true);	

		databaseAppPanel.add(scrollPane);
		databaseAppPanel.add(btnOK);
		//databaseAppPanel.add(btnBack);
		databaseAppPanel.add(btnDel);
		databaseAppPanel.add(btnAdd);
		databaseAppPanel.add(btnEdit);
	}

	public void coursesDatabaseMenuPanel(){
		currentPanel = 4;	// Set the current GUI to the courses's database menu screen(4)
		coursesAppPanel = new JPanel();
		coursesAppPanel.setLayout(null);

		Image newimg = imgOK.getScaledInstance(17, 17, java.awt.Image.SCALE_SMOOTH) ;  
		ok = new ImageIcon( newimg );
		//		Image newimg2 = imgBack.getScaledInstance(17, 17, java.awt.Image.SCALE_SMOOTH) ;  
		//		back = new ImageIcon( newimg2 );
		Image newimg3 = imgExit.getScaledInstance(17, 17, java.awt.Image.SCALE_SMOOTH) ;  
		exit = new ImageIcon( newimg3 );
		Image newimg4 = imgAdd.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH) ;  
		add = new ImageIcon( newimg4 );
		Image newimg5 = imgEdit.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH) ;  
		edit = new ImageIcon( newimg5 );
		Image newimg6 = imgDel.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH) ;  
		del = new ImageIcon( newimg6 );

		JFrame.setDefaultLookAndFeelDecorated(false);		
		coursesFrame.setLayout(null);		
		coursesFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		coursesFrame.setSize(800, 400);
		coursesFrame.setResizable(false);
		coursesFrame.setLocationRelativeTo(null);
		coursesFrame.setVisible(true);
		coursesFrame.setContentPane(coursesAppPanel);

		btnAdd = new JButton("  Add");
		btnDel = new JButton("  Delete");
		btnEdit = new JButton("  Modify");
		btnOK = new JButton ("  OK");
		//		btnBack = new JButton ("  Back");
		btnExit = new JButton ("  Exit");

		btnExit.setMnemonic('e');
		btnExit.addActionListener(this);
		btnExit.setBounds(510, 500, 130, 35);

		btnOK.setMnemonic('o');
		btnOK.addActionListener(this);
		btnOK.setBounds(640, 330, 130, 25);

		//		btnBack.setMnemonic('b');
		//		btnBack.addActionListener(this);
		//		btnBack.setBounds(20, 330, 130, 25);

		btnDel.setMnemonic('d');
		btnDel.addActionListener(this);
		btnDel.setBounds(640, 195, 130, 30);

		btnEdit.setMnemonic('e');
		btnEdit.addActionListener(this);
		btnEdit.setBounds(640, 135, 130, 30);

		btnAdd.setMnemonic('a');
		btnAdd.addActionListener(this);
		btnAdd.setBounds(640, 75, 130, 30);

		btnOK.setIcon(ok);
		//		btnBack.setIcon(back);
		btnExit.setIcon(exit);
		btnAdd.setIcon(add);
		btnDel.setIcon(del);
		btnEdit.setIcon(edit);

		Object rowData[][] = { { "11025409", "INTROSE", "S11","Syliongka, L.","CCS", "ST"},
				{ "11013133", "MICPRC1", "S12","Ong, C.","CCS", "CT"} };
		Object columnNames[] = { "ID Number", "CourseCode", "Section", "Professor", "College", "Department"};
		JTable table = new JTable(rowData, columnNames);
		JScrollPane scrollPane = new JScrollPane(table);

		scrollPane.setBounds(20, 75, 600, 240);
		scrollPane.setVisible(true);	
		coursesAppPanel.add(scrollPane);
		coursesAppPanel.add(btnOK);
		coursesAppPanel.add(btnBack);
		coursesAppPanel.add(btnDel);
		coursesAppPanel.add(btnAdd);
		coursesAppPanel.add(btnEdit);
	}

	/**
	 * memberDatabaseControl()		adding/modifying member's profile
	 * 	Initialization of the UI for the adding/modifying of member's profile
	 *  @no 10
	 */
	public void memberDatabaseControl(){
		currentPanel =10;
		addPanel = new JPanel();
		addPanel.setLayout(null);

		Image newimg = imgAdd.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH) ;  
		add = new ImageIcon( newimg );
		Image newimg2 = imgCancel.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH) ;  
		cancel = new ImageIcon( newimg2 );
		Image newimg3 = imgSave.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH) ;  
		save = new ImageIcon( newimg3 );

		String [] rankOptions = {"Member - New", "Member - Old", "Member - Honorary", "Neophyte", "Officer", "President"};

		JFrame.setDefaultLookAndFeelDecorated(false);
		addMemberFrame.setLayout(null);
		addMemberFrame.setSize(385,465);
		addMemberFrame.setResizable(false);
		addMemberFrame.setLocationRelativeTo(null);
		addMemberFrame.setVisible(true);
		addMemberFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		addMemberFrame.setContentPane(addPanel);

		btnCancel = new JButton ("Cancel");

		fname = new JLabel("First Name:");
		mname = new JLabel("Middle Name:");
		lname = new JLabel("Last Name:");
		course = new JLabel("Course:");
		bday = new JLabel("Birthday:");
		email = new JLabel("E-mail Address:");
		contact = new JLabel("Contact Information:");
		rank = new JLabel("Rank:");
		subject = new JLabel("Subject(s):");
		other = new JLabel("Other Information:");

		FnameText = new JTextField();
		MnameText = new JTextField();
		LnameText = new JTextField();
		courseText = new JTextField();
		emailText = new JTextField();
		contactText = new JTextField();
		otherText = new JTextField();

		ranks = new JComboBox(rankOptions);
		month = new JComboBox(monthName);
		year = new JComboBox();
		for (int i=1950; i<2021; i++){
			year.addItem(new Integer(i));
		}
		day = new JComboBox();

		month.addActionListener(this);
		year.addActionListener(this);
		bdayLengthControl();

		fname.setBounds(25, 50, 100, 20);
		FnameText.setBounds(155, 50, 170, 20);
		mname.setBounds(25, 80, 100, 20);
		MnameText.setBounds(155, 80, 170, 20);
		lname.setBounds(25, 110, 110, 20);
		LnameText.setBounds(155, 110, 170, 20);
		bday.setBounds(25, 140, 110, 20);
		month.setBounds(155, 140, 60, 20);
		day.setBounds(220, 140, 40, 20);
		year.setBounds(265, 140, 60, 20);
		course.setBounds(25, 170, 110, 20);
		courseText.setBounds(155, 170, 170, 20);
		email.setBounds(25, 200, 100, 20);
		emailText.setBounds(155, 200, 170, 20);
		contact.setBounds(25, 230, 150, 20);
		contactText.setBounds(155, 230, 170, 20);
		rank.setBounds(25, 260, 170, 20);
		ranks.setBounds(155, 260, 170, 20);
		subject.setBounds(25, 290, 100, 20);
		other.setBounds(25, 320, 170, 20);
		otherText.setBounds(155, 320, 170, 60);

		ranks.setSelectedIndex(5);
		ranks.addActionListener(this);

		month.setSelectedIndex(0);
		month.addActionListener(this);

		day.addActionListener(this);

		btnCancel.setMnemonic('x');
		btnCancel.addActionListener(this);
		btnCancel.setBounds(260, 390, 105, 30);

		btnCancel.setIcon(cancel);

		addPanel.add(btnCancel);
		addPanel.add(fname);
		addPanel.add(FnameText);
		addPanel.add(mname);
		addPanel.add(MnameText);
		addPanel.add(lname);
		addPanel.add(LnameText);
		addPanel.add(course);
		addPanel.add(courseText);
		addPanel.add(bday);
		addPanel.add(month);
		addPanel.add(day);
		addPanel.add(year);
		addPanel.add(email);
		addPanel.add(emailText);
		addPanel.add(contact);
		addPanel.add(contactText);
		addPanel.add(rank);
		addPanel.add(ranks);
		addPanel.add(subject);
		addPanel.add(other);
		addPanel.add(otherText);

		if (addEditFlag == 0){
			fill = new JLabel("Please fill out the form.");
			btnAdd = new JButton ("  Add");

			btnAdd.setMnemonic('b');
			btnAdd.addActionListener(this);

			fill.setBounds(10, 20, 250, 20);
			btnAdd.setBounds(155, 390, 95, 30);

			btnAdd.setIcon(add);
			addPanel.add(btnAdd);
			addPanel.add(fill);
		}
		else if (addEditFlag==1){
			fill = new JLabel("Select a user to be modified:");
			user = new JComboBox();
			btnSave = new JButton ("  Save");

			btnSave.setMnemonic('s');
			btnSave.addActionListener(this);

			user.setBounds(180, 20, 145, 20);
			fill.setBounds(10, 20, 250, 20);
			btnSave.setBounds(155, 390, 95, 30);

			btnSave.setIcon(save);
			addPanel.add(fill);
			addPanel.add(user);
			addPanel.add(btnSave);
		}
	}

	/**
	 * courseDatabaseControl()		adding/modifying course's profile
	 * 	Initialization of the UI for the adding/modifying of course's profile
	 *  @no 11
	 */
	public void courseDatabaseControl(){
		currentPanel = 11;
		addcoursePanel = new JPanel();
		addcoursePanel.setLayout(null);
		
		Image newimg = imgAdd.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH) ;  
		add = new ImageIcon( newimg );
		Image newimg2 = imgCancel.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH) ;  
		cancel = new ImageIcon( newimg2 );
		
		String [] rankOptions = {"Member", "Officer"};
		
		JFrame.setDefaultLookAndFeelDecorated(false);
		addcourseFrame.setLayout(null);
		addcourseFrame.setSize(385,300);
		addcourseFrame.setResizable(false);
		addcourseFrame.setLocationRelativeTo(null);
		addcourseFrame.setVisible(true);
		addcourseFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		addcourseFrame.setContentPane(addcoursePanel);
				
		btnAdd = new JButton ("  Add");
		btnCancel = new JButton ("Cancel");
		
		fill = new JLabel("Please fill out the form.");
		coursecode = new JLabel("Course Code:");
		section = new JLabel("Section:");
		professor = new JLabel("Professor:");
		college = new JLabel("College:");
		department = new JLabel("Department: ");
				
		coursecodeText = new JTextField();
		sectionText = new JTextField();
		professorText = new JTextField();
		collegeText = new JTextField();
		departmentText = new JTextField();
		
		fill.setBounds(10, 20, 250, 20);
		coursecode.setBounds(25, 50, 100, 20);
		coursecodeText.setBounds(155, 50, 170, 20);
		section.setBounds(25, 80, 100, 20);
		sectionText.setBounds(155, 80, 170, 20);
		professor.setBounds(25, 110, 150, 20);
		professorText.setBounds(155, 110, 170, 20);
		college.setBounds(25, 140, 150, 20);
		collegeText.setBounds(155, 140, 170, 20);
		department.setBounds(25, 170, 100, 20);
		departmentText.setBounds(155, 170, 170, 20);

		btnAdd.setMnemonic('b');
		btnAdd.addActionListener(this);
		btnAdd.setBounds(155, 220, 95, 30);
		
		btnCancel.setMnemonic('x');
		btnCancel.addActionListener(this);
		btnCancel.setBounds(260, 220, 105, 30);

		btnAdd.setIcon(add);
		btnCancel.setIcon(cancel);
		
		addcoursePanel.add(btnCancel);
		addcoursePanel.add(btnAdd);
		addcoursePanel.add(fill);
		addcoursePanel.add(coursecode);
		addcoursePanel.add(coursecodeText);
		addcoursePanel.add(section);
		addcoursePanel.add(sectionText);
		addcoursePanel.add(professor);
		addcoursePanel.add(professorText);
		addcoursePanel.add(college);
		addcoursePanel.add(collegeText);
		addcoursePanel.add(department);
		addcoursePanel.add(departmentText);
	}
	
	/**
	 * bdayLengthControl()
	 *  class for determining the correct range for the birthday (day) combo box during adding/modifying a member's profile
	 */
	public void bdayLengthControl(){
		Integer o = ((Integer)year.getSelectedItem());
		int finalYear = o.intValue();
		String m = ((String)month.getSelectedItem());
		int max=0;	

		if(m.equals("Apr")||m.equals("Jun")||m.equals("Sept")||m.equals("Nov"))
			max=30;
		else if(m.equals("Jan")||m.equals("Mar")||m.equals("May")||m.equals("Jul")||m.equals("Aug")||m.equals("Oct")||m.equals("Dec"))
			max=31;
		else if (m.equals("Feb")){
			if(finalYear%4==0)
				max=29;
			else
				max=28;
		}

		day.removeAllItems();
		for (int i=1; i<=max; i++){
			day.addItem(i);
		}
	}

	public void actionPerformed(ActionEvent arg0) {
		Object source = arg0.getSource();

		if (source == btnExit){
			windowClosing(null);
		}
		else{
			switch(currentPanel){
			case 1:	// Main Menu
				if  (source == btnEdit){
					modifyDatabaseMenuPanel();
					currentPanel = 2;
					mainFrame.dispose();
				}
				else if (source == btnNew){
					newDatabaseCreationPanel();
					currentPanel = 7;
					mainFrame.dispose();
				}
				break;
			case 2: // Database Primary Menu 
				if (source == btnBack){
					mainMenuPanel();
					currentPanel = 1;
					modifyFrame.dispose();
				}
				else if (source == btnMembers){
					memberDatabaseMenuPanel();
					currentPanel = 3;	// Set the current GUI to the member's database menu screen(3)
					modifyFrame.dispose();
				}
				else if (source == btnCourses){
					coursesDatabaseMenuPanel();
					currentPanel = 4;	// Set the current GUI to the Courses's database menu screen(4)
					modifyFrame.dispose();
				}
				else if (source == btnIncentives){
					/////////////////////////////////////////////
					currentPanel = 5;	// Set the current GUI to the Incentives's database menu screen(5)
					modifyFrame.dispose();
				}
				else if (source == btnNotes){
					////////////////////////////////////////////
					currentPanel = 6;	// Set the current GUI to the Notes menu screen(6)
					modifyFrame.dispose();
				}
				else if (source == btnBrowse){
					FileDialog fd = new FileDialog(modifyFrame, "Load File From..", FileDialog.LOAD);
					fd.setVisible(true);
					System.out.println(fd.getFile());	
				}
				break;
			case 3: //Members database Primary menu
				if(source == btnOK){
					currentPanel = 2;
					modifyDatabaseMenuPanel();
					databaseFrame.dispose();			
				}

				else if (source == btnAdd){
					addEditFlag = 0;
					currentPanel = 10;
					memberDatabaseControl();
					databaseFrame.dispose();
				}

				else if (source == btnEdit){
					addEditFlag = 1;
					currentPanel = 10;
					memberDatabaseControl();
					databaseFrame.dispose();
				}
				break;
			case 4: //Courses database Primary menu
				if(source == btnOK){
					currentPanel = 2;
					modifyDatabaseMenuPanel();
					coursesFrame.dispose();					
				}
				else if (source == btnAdd){
					//					new addcourseAppUI();
					coursesFrame.dispose();
				}
				else if (source == btnEdit){

				}
				break;
			case 7: //New Database File Primary Menu
				if (source == btnLoad){
					currentPanel = 9;
					newDatabaseCreationFromCSVPanel();
					newDatabaseFileframe.dispose();			
				}
				else if (source == btnSave){
					currentPanel = 8;
					newDatabaseCreationFromNewPanel();
					newDatabaseFileframe.dispose();
				}
				else if (source == btnBack){
					mainMenuPanel();
					currentPanel = 1;
					newDatabaseFileframe.dispose();
				}
				break;
			case 8: //New Database File Secondary (Manual New) Menu
				if (source == btnC){
					newDatabaseCreationPanel();
					currentPanel = 7;
					newDatabaseViaManualFrame.dispose();	
				}
				else if(source == btnOK){
					if(txtSave.getText().equals(null) || txtSave.getText().equals("")){
						JOptionPane.showMessageDialog(btnOK, "ERROR: Invalid Save/Load Location","ERROR", JOptionPane.ERROR_MESSAGE);
					}
					else{
						if(JOptionPane.showConfirmDialog(null, "Are you sure that this is correct?", "Are you sure?", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
							JOptionPane.showMessageDialog(btnOK, "Database file has been created.");
							modifyDatabaseMenuUIPanel(fLocation);
							newDatabaseViaManualFrame.dispose();
						}		
					}			
				}

				else if(source == btnS){
					FileDialog fd = new FileDialog(newDatabaseViaCSVFrame, "Save Database To..", FileDialog.SAVE);
					fd.setVisible(true);
					txtSave.setText(fd.getDirectory() + fd.getFile());
					fLocation = new File ("fd.getDirectory() + fd.getFile()");
					if(!fLocation.canWrite()){
						JOptionPane.showMessageDialog(btnOK, "ERROR: Can not save to the specific location","ERROR", JOptionPane.ERROR_MESSAGE);
						txtSave.setText("");
					}
					System.out.println(fd.getDirectory() + fd.getFile());							
				}
				break;
			case 9: //New Database File Secondary (Load from CSV) Menu
				if (source == btnC){ 
					newDatabaseCreationPanel();
					currentPanel = 7;
					newDatabaseViaCSVFrame.dispose();	
				}
				else if(source == btnOK){
					if(txtSave.getText().equals(null) || txtSave.getText().equals("") || txtLoad.getText().equals(null) || txtLoad.getText().equals("")){
						JOptionPane.showMessageDialog(btnOK, "ERROR: Invalid Save/Load Location","ERROR", JOptionPane.ERROR_MESSAGE);
					}
					else{
						if(JOptionPane.showConfirmDialog(null, "Are you sure that this is correct?", "Are you sure?", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
							JOptionPane.showMessageDialog(btnOK, "Database file has been created.");
							currentPanel = 2;
							modifyDatabaseMenuUIPanel(fLocation);
							newDatabaseViaCSVFrame.dispose();
						}		
					}
				}
				else if(source == btnL){
					FileDialog fd = new FileDialog(newDatabaseViaCSVFrame, "Load Database From..", FileDialog.LOAD);
					fd.setVisible(true);
					txtLoad.setText(fd.getDirectory() + fd.getFile());
					fLoad = new File ("fd.getDirectory() + fd.getFile()");
					if(!fLoad.canRead()){
						JOptionPane.showMessageDialog(btnOK, "ERROR: File is locked","ERROR", JOptionPane.ERROR_MESSAGE);
						txtLoad.setText("");
					}
					System.out.println(fd.getDirectory() + fd.getFile());							
				}
				else if(source == btnS){
					FileDialog fd = new FileDialog(newDatabaseViaCSVFrame, "Save Database To..", FileDialog.SAVE);
					fd.setVisible(true);
					txtSave.setText(fd.getDirectory() + fd.getFile());
					fLocation = new File ("fd.getDirectory() + fd.getFile()");
					if(!fLocation.canWrite()){
						JOptionPane.showMessageDialog(btnOK, "ERROR: Can not save to the specific location","ERROR", JOptionPane.ERROR_MESSAGE);
						txtSave.setText("");
					}
					System.out.println(fd.getDirectory() + fd.getFile());						
				}
				break;
			case 10: // Add or Modify of Member's Data
				if (source == btnAdd){
					if(JOptionPane.showConfirmDialog(null, "Are you sure that this is correct?", "Are you sure?", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
						JOptionPane.showMessageDialog(null, "Data has been saved.");
					}	
				}

				else if (source == btnCancel){
					currentPanel = 3;
					memberDatabaseMenuPanel();
					addMemberFrame.dispose();
				}

				else if (source == btnSave){
					if(JOptionPane.showConfirmDialog(null, "Are you sure that this is correct?", "Are you sure?", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
						JOptionPane.showMessageDialog(null, "Data has been saved.");
					}
					//Adding if addEdit is 0 or Modify if addEdit is 1 member to the memberInfo Vector
					//SQL STATEMENT ADD/MODIFY HERE
					currentPanel = 3;
					memberDatabaseMenuPanel();
					addMemberFrame.dispose();
				}

				else if (source == month || source == year){
					bdayLengthControl();
				}
				break;
			case 11: // Add or Modify of Course's Data
				if (source == btnAdd){
					if(JOptionPane.showConfirmDialog(null, "Are you sure that this is correct?", "Are you sure?", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
						JOptionPane.showMessageDialog(null, "Data has been saved.");
					}	
					//Adding if addEdit is 0 or Modify if addEdit is 1 member to the courseInfo Vector
					//SQL STATEMENT ADD/MODIFY HERE
					currentPanel = 4;
					courseDatabaseControl();
					addcourseFrame.dispose();
				}
			
				else if (source == btnCancel){
					currentPanel = 4;
					courseDatabaseControl();
					addcourseFrame.dispose();
				}
				break;
			}
		}

	}


	public void windowActivated(WindowEvent e) {
	}
	public void windowClosed(WindowEvent e) {
	}
	public void windowClosing(WindowEvent e) {
		if(JOptionPane.showConfirmDialog(null, "Are you sure you want to exit?", "Are you sure?", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
			System.exit(0);
		}
	}

	public void windowDeactivated(WindowEvent e) {
	}
	public void windowDeiconified(WindowEvent e) {
	}
	public void windowIconified(WindowEvent e) {
	}
	public void windowOpened(WindowEvent e) {
	}

}
